package com.ptszyxx.popose.common.utils;

import android.util.Log;

import com.ptszyxx.popose.common.enums.ActionEnum;
import com.ysg.base.BaseViewModel;
import com.ysg.http.BaseResponse;
import com.ysg.http.HttpUtils;
import com.ysg.http.callback.OnSuccessResult;
import com.ysg.http.data.CommonRepository;
import com.ysg.utils.YChannelUtil;
import com.ysg.utils.YPhoneUtil;
import com.ysg.utils.YSPUtils;
import com.ysg.utils.YStringUtil;

import java.util.HashMap;
import java.util.Map;

public class YWhiteIpUtil {

    private static YWhiteIpUtil instance;

    private YWhiteIpUtil(){
    }

    public static YWhiteIpUtil getInstance(){
        if (instance == null){
            synchronized (YWhiteIpUtil.class){
                if (instance == null){
                    instance = new YWhiteIpUtil();
                }
            }
        }
        return instance;
    }


    /**
     * 白名单ip
     */
    public void requestIsWhiteIp(BaseViewModel viewModel, CommonRepository model) {
        String phone = YSPUtils.getInstance().getUserPhone();
        if (YStringUtil.isNotEmpty(phone)){
            Map<String, String> map = new HashMap<>();
            map.put("account", phone);
            map.put("platform", YChannelUtil.getInstance().getPlatform());

            HttpUtils.getInstance()
                    .data(model.isWhiteIp(map), viewModel,
                            new OnSuccessResult<Boolean>() {
                                @Override
                                public void onSuccessResult(BaseResponse<Boolean> response) {
                                    Boolean data = response.getData();
                                    YSPUtils.getInstance().saveWhiteIp(data);
                                    Log.e("ip是否为白名单", ""+data);
                                }
                            });

        }
    }


}
